#pragma once

#include "CInterlockedReferenceCount.h"

class AtlasNode;

class TextureAtlas :
	public CInterlockedReferenceCount
{
public: 
	virtual XUINT32 AddRef();
	virtual XUINT32 Release();
	HRESULT CreateView(XUINT32 width, XUINT32 height, XUINT32 includePadding, AtlasNode * * ppView);
	void ReleaseView(AtlasNode * pNodeToRemove);
	struct IPALSharedSurface * GetSurface();
	static void AddPadding(XUINT8 * pAddress, XUINT32 width, XUINT32 height, XINT32 stride, XUINT32 pixelStride, const struct XRECT_WH & lockedRect, const struct XRECT_WH & atlasSubrect, struct XRECT_WH * pDirtyRect);
	void TraceMemoryUsage();

protected: 
	TextureAtlas(enum PixelFormat pixelFormat);
	virtual ~TextureAtlas();
	HRESULT Init(const struct XRECT_WH & bounds);
public: 
	static const XUINT32 AtlasMaxTextureSize;
	static const XUINT32 AtlasMinTextureHeight;
	static const XINT32 TileSize;
protected: 
	enum PixelFormat m_pixelFormat;
	struct IPALSharedSurface * m_pSurface;
	AtlasNode * m_pAtlasRoot;
	XUINT32 m_utilizedSpace;
};